#***********************************************************************************************************************
#*	filename: Makefile
#*	date: 2018-10-15 by Echo Zhang @ HanClouds
#***********************************************************************************************************************

TARGET ?= http_download
SUFFIX ?= 

BUILD_DIR = build
INCLUDE_PATH =

CROSS_COMPILE = 
#CROSS_COMPILE = 
CC = $(CROSS_COMPILE)gcc
OBJCOPY = $(CROSS_COMPILE)objcopy
SIZE = $(CROSS_COMPILE)size


#source file
SRC_DIR = .
SRC_DIR_FILE = main.c
INCLUDE_PATH += -I ${SRC_DIR}
SOURCE_FILE += $(addprefix $(SRC_DIR)/, $(basename $(SRC_DIR_FILE)))

CORE_DIR = core
CORE_DIR_FILE = dbg.c cfg_info.c cJSON.c crc16.c tick.c
INCLUDE_PATH += -I ${CORE_DIR}
SOURCE_FILE += $(addprefix $(CORE_DIR)/, $(basename $(CORE_DIR_FILE)))

NET_DIR = network
NET_DIR_FILE = http_client.c update.c
INCLUDE_PATH += -I ${NET_DIR}
SOURCE_FILE += $(addprefix $(NET_DIR)/, $(basename $(NET_DIR_FILE)))

OBJ_FILE = $(addsuffix .o, $(basename $(SOURCE_FILE)))
OBJ_FILE_PATH = $(addprefix ${BUILD_DIR}/, $(OBJ_FILE))

CFLAGS += -Wall -g  -I.
LDFLAGS = -lm -lpthread


PACKAGE_BUILD_DATE ?= \"`date +%F\ %T`\"


.PHONY: size all clean

target: mkdir ${BUILD_DIR}/$(TARGET)$(SUFFIX)

all: clean target

mkdir:
	mkdir -p ${BUILD_DIR}/$(NET_DIR)
	mkdir -p ${BUILD_DIR}/$(CORE_DIR)

${BUILD_DIR}/$(TARGET)$(SUFFIX): $(OBJ_FILE_PATH)
	$(CC) $(CFLAGS) $(OBJ_FILE_PATH) -o "$@" $(LDFLAGS)

${BUILD_DIR}/%.o: %.c
	$(CC) -c -o "$@" $(CFLAGS) $<

clean:
	rm -fr ${BUILD_DIR}/*
install:
	sudo sshpass -p 'csg2020' scp ${BUILD_DIR}/$(TARGET)$(SUFFIX) root@192.168.2.219:/root


#***********************************************************************************************************************
#*	endline
#***********************************************************************************************************************
